#!/usr/bin/env python3
# -*- encoding=utf-8 -*-

# install requires
# pip3 install elasticsearch==7.13.0 --target=/usr/local/lib/python3.7/site-packages
# pip3 install PyYAML --target=/usr/local/lib/python3.7/site-packages

# Usage:
#   reproducible-test matrix.yaml testbox=dc-4g docker_image=openeuler:20.03-LTS-SP1 queue=dc-4g-lwt
#   reproducible-test matrix.yaml
#   eg: matrix.yaml
#   submit:
#     - rpmbuild.yaml upstream_repo=p/pigz/pigz upstream_commit=2430e2fabefabddc2a132edcb4bb122d91a68796 upstream_url=https://gitee.com/src-openeuler/pigz
#     - rpmbuild.yaml upstream_repo=m/minicom/minicom upstream_commit=4baeee2da62fd813cd604fc06218af017ba2283b upstream_url=https://gitee.com/src-openeuler/minicom
#   default_param:
#     runtime: 30
#   common_param:
#     arch:
#       - aarch64
#       - x86_64
#     upstream_branch: openEuler-20.03-LTS-SP1
#     custom_repo_name: experimental/budding-openeuler
#     group_id: reproducible-build-2022-3-17
#     upload_rpm_to_result_root: on
#     normal_upload_rpm: off

import sys
import os
import argparse

CURRENT_FILE_DIR = os.path.dirname(os.path.abspath(__file__))

sys.path.append(f"{CURRENT_FILE_DIR}/")
from reproducible_test import *

#import elasticsearch


def params_check(argv):
    is_correct = True
    if len(argv) != 2:
        is_correct = False
    if not (argv[1].endswith('.json') or argv[1].endswith('.yaml')):
        is_correct =False

    return is_correct

if __name__ == "__main__":
    argv = sys.argv
    if not params_check(argv):
        print("incorrect usage!")
        print("Usage like: reproducible-test matix.yaml/matrix.json")
    ids = submit_jobs(argv[1])
    #ids = ['z9.14906118', 'z9.14921685', 'z9.14906120','z9.14921690']
    #ids = load_config_file('./a3.json')
    wait(ids)
